/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package beans.enitites;

import com.mysql.jdbc.util.TimezoneDump;
import hirondelle.date4j.DateTime;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 *
 * @author marcy
 */
public class ExaminationBean extends db.entities.Examination {

    private int patientId;
    private List<ExaminationBean> patientOldExaminations;
    private List<ExaminationBean> patientNewExaminations;
    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");

    public ExaminationBean() {
    }

    public boolean colore(Date date) {
        DateTime now = DateTime.now(TimeZone.getDefault());
        DateTime scadenza = new DateTime(sdf.format(date));

        return scadenza.lteq(now.plusDays(7));

    }

    public List<ExaminationBean> getPatientOldExaminations() {
        if (patientOldExaminations == null) {
            EntityManagerFactory emf = Persistence.createEntityManagerFactory("PortaleVisitePU");
            EntityManager em = emf.createEntityManager();
            this.patientOldExaminations = (List<ExaminationBean>) em.createNamedQuery("Examination.alreadyDoneByPat", ExaminationBean.class).setParameter("id", patientId).getResultList();
        }
        return patientOldExaminations;
    }

    public void setPatientOldExaminations(List<ExaminationBean> patientExaminations) {
        this.patientOldExaminations = patientExaminations;
    }

    public List<ExaminationBean> getPatientNewExaminations() {
        if (patientNewExaminations == null) {
            EntityManagerFactory emf = Persistence.createEntityManagerFactory("PortaleVisitePU");
            EntityManager em = emf.createEntityManager();
            this.patientNewExaminations = (List<ExaminationBean>) em.createNamedQuery("Examination.notYetDoneByPat", ExaminationBean.class).setParameter("id", patientId).getResultList();
        }
        return patientNewExaminations;
    }

    public void setPatientNewExaminations(List<ExaminationBean> patientNewExaminations) {
        this.patientNewExaminations = patientNewExaminations;
    }

    public int getPatientId() {
        return patientId;
    }

    public void setPatientId(int patientId) {
        this.patientId = patientId;
    }
}
